package cn.chencq.gdt.vo;

import java.util.LinkedList;
import java.util.Set;

import cn.chencq.gdt.utils.Utils;

public class ProxyQueue {
	private static LinkedList<ProxyIp> proxyQueue = new LinkedList<ProxyIp>();

	/**
	 * 队尾添加数据
	 * 
	 * @param proxyIp
	 */
	public synchronized static void push(ProxyIp proxyIp) {
		proxyQueue.add(proxyIp);
	}

	/**
	 * 队头取出数据
	 * 
	 * @return
	 */
	public synchronized static ProxyIp pop() {
		if (proxyQueue.isEmpty()) {// 如果为空获取数据
			Set<ProxyIp> proxys = Utils.getProxyIpByTk();
			for (ProxyIp proxy : proxys) {
				proxyQueue.add(proxy);
			}
		}
		return proxyQueue.removeFirst();
	}

	public synchronized static boolean isEmpty() {
		return proxyQueue.isEmpty();
	}

	public static int size() {
		return proxyQueue.size();
	}

}
